package com.glq1218.common.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author glq1218
 */
@Data
@Configuration
public class CosConfig {
    @Value("${tencent.cos.secretId}")
    private String secretId;
    @Value("${tencent.cos.secretKey}")
    private String secretKey;
    @Value("${tencent.cos.bucketName}")
    private String bucketName;
    @Value("${tencent.cos.region}")
    private String region;

    @Bean
    public COSClient cosClient() {
        // 初始化用户信息
        COSCredentials cosCredentials = new BasicCOSCredentials(this.secretId, this.secretKey);
        // 设置地域
        Region region = new Region(this.region);
        ClientConfig config = new ClientConfig(region);
        // 生成COS客户端
        return new COSClient(cosCredentials, config);
    }
}

